<?php
include_once '../inc/config.inc.php';
include_once '../inc/mysql.inc.php';
include_once 'inc/tool.inc.php';
$link=connect();
include_once 'inc/is_manage_login.inc.php';//验证管理员是否登录

if(isset($_POST['submit'])){
	//转义入库
	$_POST=escape($link,$_POST);
	include 'inc/check_user.inc.php';
	$query="insert into userinfo(username,password,register_time,email,phone,QQ,sex) values('{$_POST['name']}',md5({$_POST['pw']}),now(),'{$_POST['email']}','{$_POST['phone']}','{$_POST['QQ']}','{$_POST['sex']}')";
	execute($link,$query);
	if(mysqli_affected_rows($link)==1){
		skip('user_List.php','ok','恭喜你，添加成功！');
	}else{
		skip('user_add.php','error','对不起，添加失败，请重试！');
	}
}
$template['title']='用户添加页';
$template['css']=array('style/public.css');
?>
<?php include 'inc/header.inc.php'?>
<div id="main">
	<div class="title" style="margin-bottom:20px;">添加用户</div>
	<form method="post">
		<table class="au">
			<tr>
				<td>用户名称</td>
				<td><input name="name" required="required" placeholder="请输入用户名称" maxlength="12"  type="text" /></td>
				<td>
					名称不得为空，不得超过12个字符
				</td>
			</tr>
			<tr>
				<td>密码</td>
				<td><input name="pw" required="required" maxlength="18" placeholder="请输入密码" type="password" /></td>
				<td>
					密码不能少于6位或大于18位
				</td>
			</tr>
			<tr>
				<td>电子邮箱</td>
				<td><input name="email" required="required" placeholder="请输入电子邮箱" type="email" /></td>
				<td>
					输入合法的电子邮件
				</td>
			</tr>
			<tr>
				<td>手机号</td>
				<td><input name="phone" required="required" maxlength="12" placeholder="请输入手机号" type="tel" /></td>
				<td>
					输入正确的手机号
				</td>
			</tr>
			<tr>
				<td>QQ</td>
				<td><input name="QQ" required="required" maxlength="12" placeholder="请输入QQ" type="text" /></td>
				<td>
					输入正确的QQ
				</td>
			</tr>
			<tr>
				<td>性别</td>
				<td><select name="sex">
						<option value="男">男</option>
						<option value="女">女</option>
					</select>
				</td>
			</tr>
		</table>
		<input style="margin-top:20px;cursor:pointer;" class="btn" type="submit" name="submit" value="添加" />
	</form>
</div>
<?php include 'inc/footer.inc.php'; close($link);?>